//测试的token、roomId
function getRequests() {

    var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNzM2MzI4NTIiLCJiYXRjaCI6Ii0xIiwiZXhwIjoxNTY0MTI2ODI1fQ.U-dJxLHQQE6_noe2olswiduW6IB2xO2sS13Z-u80ghM",
        userid = "32496766";

    // 获取token
    // if (bridge.call("account.getToken", null)) {
    //     token = bridge.call("account.getToken", null);
    // }
    // if (bridge.call("account.getUid", null)) {
    //     userid = bridge.call("account.getUid", null)
    // }
    if (token) {
        localStorage.setItem("token", token);
    }
    if (userid) {
        localStorage.setItem("userid", userid);
    }
    var roomId = getQueryString("roomId");
    // url = "http://47.112.149.8:8086"; localStorage.getItem("token")
    var requests = {
        // 分享接口：
        shareUrl: "http://47.112.149.8:8086/room/share?roomId=" + roomId,
        // 家族管理列表：
        searchFamily: "http://47.112.149.8:8084/family/searchFamily",
        // 获取房间榜单接口：
        getRoomRankingList: "http://47.112.149.8:8082/giftOrder/getRoomRankingList",
        // 申请进家族：
        joinFamily: "http://47.112.149.8:8084/family/joinFamily",

        // 未成年认证：
        nonageIdentification: "http://47.112.149.8:8084/nonageIdentification",
        // 提现记录：
        getSubmitRecord: "http://47.112.149.8:8084/getSubmitRecord",
        // 获取验证码
        smscode: "http://47.112.149.8:8084/account/smscode",
        // 绑定手机号
        bindingMobile: "http://47.112.149.8:8084/bindingMobile",
        // 用户可提现余额
        getBalance: "http://47.112.149.8:8084/getBalance",
        // 判断提现跳转路由：
        isBinding: "http://47.112.149.8:8084/isBinding",
        // 实名认证：
        identityVerify: "http://47.112.149.8:8084/identityVerify",
        // 绑定银行卡：
        bindingBankCard: "http://47.112.149.8:8084/bindingBankCard",
        //银行卡
        getBank: "http://47.112.149.8:8084/getBank",
        // 退出家族：
        outFamily: "http://47.112.149.8:8084/family/outFamily",
        // 收益记录、收益详情接口：
        getEarningsRecord: "http://47.112.149.8:8084/getEarningsRecord",

        token: localStorage.getItem("token"),
        keyword: getQueryString("family_id"),
        roomId: roomId,
        family_id: getQueryString("family_id"),
        userid: localStorage.getItem("userid")
    };
    return requests;
}
// 隐藏loading：
function hideLoadingDialog(msg) {
    bridge.call("app.hideLoadingDialog", msg);
}
// 显示loading
function showLoadingDialog(msg) {
    bridge.call("app.showLoadingDialog", msg);
}
// 关闭web页面
function finishPage(msg) {
    bridge.call("app.finishPage", msg);
}

/*bridge.call("app.showMsg",img); 显示toast信息*/
function showMsg(msg) {
    bridge.call("app.showMsg", msg);
}
// 显示用户主页
function userHomepage(uid) {
    bridge.call("app.userHomepage", JSON.stringify({ "uid": uid }));
}

function closeYeMian() {
    // 重置window.opener用来获取打开当前窗口的窗口引用
    　　 // 这里置为null,避免IE下弹出关闭页面确认框
    window.opener = null;
    // JS重写当前页面
    window.open("", "_self", "");
    // 顺理成章的关闭当前被重写的窗口
    window.close();
}



// onkeydown="isOnkeydown()" 时时监听 当是11位手机号时的回调：
function isOnkeydown(e) {
    var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
    if (!!(reg.test(mobile))) {
        return true
    }

}

// 判断手机号是否是正确的
function isPhoneTel(str) {
    var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
    if (reg.test(str)) {
        return true;
    } else {
        return false;
    }
}

// 验证身份证号码是否正确
function getShengFengZheng(str) {
    var reg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
    if (reg.test(str)) {
        return true;
    } else {
        return false;
    }
}

// 获取URL上的参数：

function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

// 格式化时间：
function formatTime(time, cFormat) {
    if (arguments.length === 0) return null
    if ((time + '').length === 10) {
        time = +time * 1000
    }

    var format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}',
        date
    if (typeof time === 'object') {
        date = time
    } else {
        date = new Date(time)
    }

    var formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay()
    }
    var time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
        var value = formatObj[key]
        if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
        if (result.length > 0 && value < 10) {
            value = '0' + value
        }
        return value || 0
    })
    return time_str
}

// 切割数组
function chunk(arr, size) {
    var rsArr = [];
    for (var i = 0; i < arr.length; i += size) {
        var tempArr = [];
        for (var j = 0; j < size && i + j < arr.length; j++) {
            tempArr.push(arr[i + j]);
        }
        rsArr.push(tempArr);
    }
    return rsArr;
}

export default {
    getRequests: getRequests()
}